package com.cn.hjsj.appInterface;

import com.cn.hjsj.base.annotation.Permission;
import com.cn.hjsj.util.log.LogUtil;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.cn.hjsj.util.CheckUtil;
/**
 * Created by lutao on 2017/02/09.
 */

@Controller
@RequestMapping("/HJSJInterface")
public class UserInterface extends AllResource{

    /*
     * function:serialBinding
     * param:String jsonstring
     * 串号绑定
     * author :lutao
     */
    @RequestMapping(value="/serialBinding")
    @ResponseBody
    @Permission("login")
    public Object serialBinding(@RequestBody String jsonstring){
    	LogUtil.info("/serialBinding>>>" + jsonstring);
    	Map<String, Object>  map=new HashMap<String,Object>();
    	try {
	        JSONObject object = JSONObject.fromObject(jsonstring);
	        ArrayList<String> arraylist =new ArrayList<String>();
            arraylist.add("productImei");
            boolean flag = CheckUtil.checkParameter(object,arraylist);
            if(!flag){
                LogUtil.error("参数输入错误");
                map.put("code", 20002);
                map.put("mes", "参数输入错误");
                return  map;
            }
            map=appImei_bundleService.SerialBinding(object);
    	}catch(Exception e){
    		LogUtil.error(e.getMessage());
            map.put("code", 30000);
            map.put("mes", e.getMessage());
    	}
    	return map;
    }
    /**
     * 串号解除绑定
     * @function  unbinding
     * @author lutao
     * @createTime 2017年2月24日
     * @param 
     */
    @RequestMapping(value="/unbinding")
    @ResponseBody
    @Permission("login")
    public Object unbinding(@RequestBody String jsonstring){
    	LogUtil.info("/unbinding>>>" + jsonstring);
    	Map<String, Object> map=new HashMap<String,Object>();
    	try {
	    	JSONObject object = JSONObject.fromObject(jsonstring);
	        ArrayList<String> arraylist =new ArrayList<String>();
            arraylist.add("id");
            boolean flag = CheckUtil.checkParameter(object,arraylist);
            if(!flag){
                LogUtil.error("参数输入错误");
                map.put("code", 20002);
                map.put("mes", "参数输入错误");
                return  map;
            }
            map=appImei_bundleService.UnBinding(object);
    	}catch(Exception e){
    		LogUtil.error(e.getMessage());
            map.put("code", 30000);
            map.put("mes", e.getMessage());
    	}
    	return map;
    }
    
    /**
     * 保修期
     * @function  insuredList
     * @author lutao
     * @createTime 2017年2月24日
     * @param 
     */
    @RequestMapping(value="/insuredList")
    @ResponseBody
    @Permission("login")
    public Object insuredList(@RequestBody String jsonstring){
    	LogUtil.info("/insuredList>>>" + jsonstring);
    	Map<String, Object>  map=new HashMap<String,Object>();
    	try {
	        JSONObject object = JSONObject.fromObject(jsonstring);
	        System.out.println("------object:"+object.toString());
            map=appImei_bundleService.InsuredList(object);
    	}catch(Exception e){
    		LogUtil.error(e.getMessage());
            map.put("code", 30000);
            map.put("mes", e.getMessage());
    	}
    	return map;
    }
    
    
    
    /**
     * 获取服务类型
     * @function  getServiceType
     * @author lutao
     * @createTime 2017年2月24日
     * @param 
     */
    @RequestMapping(value="/getServiceType")
    @ResponseBody
    @Permission("login")
    public Object getServiceType(@RequestBody String jsonstring){
    	LogUtil.info("/getServiceType>>>" + jsonstring);
    	Map<String, Object>  map=new HashMap<String,Object>();
    	try {
    		JSONObject object = JSONObject.fromObject(jsonstring);
            map=appServiceTypeService.getServiceType(object);	        
    	}catch(Exception e){
    		LogUtil.error(e.getMessage());
            map.put("code", 30000);
            map.put("mes", e.getMessage());
    	}
    	return map;
    }
    /**
     * 图片上传
     * @function  pictureUpload
     * @author lutao
     * @createTime 2017年2月28日
     * @param 
     */
    @RequestMapping(value="/pictureUpload")
    @ResponseBody
    @Permission("login")
    public Object pictureUpload(@RequestBody String jsonstring){
    	LogUtil.info("/pictureUpload>>>" + jsonstring);
    	Map<String, Object>  map=new HashMap<String,Object>();
    	try {
	    	JSONObject object = JSONObject.fromObject(jsonstring);
	        ArrayList<String> arraylist =new ArrayList<String>();
            arraylist.add("photo1");
            boolean flag = CheckUtil.checkParameter(object,arraylist);
            if(!flag){
                LogUtil.error("参数输入错误");
                map.put("code", 20002);
                map.put("mes", "参数输入错误");
                return  map;
            }
            map=appPictureUploadService.pictureUpload(object);
    	}catch(Exception e){
    		LogUtil.error(e.getMessage());
            map.put("code", 30000);
            map.put("mes", e.getMessage());
    	}
    	return map;
    }
    
    /**
     * 门店选择
     * @function  getSite
     * @author lutao
     * @createTime 2017年3月1日
     * @param 
     */
    @RequestMapping(value="/getSite")
    @ResponseBody
    @Permission("login")
    public Object getSite(@RequestBody String jsonstring){
    	LogUtil.info("/getSite>>>" + jsonstring);
    	Map<String, Object>  map=new HashMap<String,Object>();
    	try {
	    	JSONObject object = JSONObject.fromObject(jsonstring);
	        ArrayList<String> arraylist =new ArrayList<String>();
            arraylist.add("latitudeX");
            arraylist.add("longitudeY");
            boolean flag = CheckUtil.checkParameter(object,arraylist);
            if(!flag){
                LogUtil.error("参数输入错误");
                map.put("code", 20002);
                map.put("mes", "参数输入错误");
                return  map;
            }
            map=appStoreService.getSite(object);
    	}catch(Exception e){
    		LogUtil.error(e.getMessage());
            map.put("code", 30000);
            map.put("mes", e.getMessage());
    	}
    	return map;
    }
    
    /**
     * 服务单提交
     * @function  subRepair
     * @author lutao
     * @createTime 2017年3月1日
     * @param 
     * @problem 接口文档中中没有加serviceType参数
     * 			该接口需要mock用户信息
     */
    @RequestMapping(value="/subRepair")
    @ResponseBody
    @Permission("login")
    public Object subRepair(@RequestBody String jsonstring){
    	LogUtil.info("/subRepair>>>" + jsonstring);
    	Map<String, Object>  map=new HashMap<String,Object>();
    	try {
	    	JSONObject object = JSONObject.fromObject(jsonstring);
	        ArrayList<String> arraylist =new ArrayList<String>();
            arraylist.add("productName");
            arraylist.add("serviceType");
            arraylist.add("newTime");
            arraylist.add("subNumber");
            arraylist.add("description");
            arraylist.add("photoName1");
            arraylist.add("voucher");
            arraylist.add("pickupCode");
            arraylist.add("pickupName");
            arraylist.add("pickupAddress");
            arraylist.add("deliveryAddress");
            arraylist.add("siteCode");
            arraylist.add("siteTel");   
            boolean flag = CheckUtil.checkParameter(object,arraylist);
            if(!flag){
                LogUtil.error("参数输入错误");
                map.put("code", 20002);
                map.put("mes", "参数输入错误");
                return  map;
            }
            map=appRepairsService.subRepair(object);
    	}catch(Exception e){
    		LogUtil.error(e.getMessage());
            map.put("code", 30000);
            map.put("mes", e.getMessage());
    	}
    	return map;
    }
 
    /**
     * 售后网店
     * @function  getOutlets
     * @author lutao
     * @createTime 2017年3月1日
     * @param 
     */
    @RequestMapping(value="/getOutlets")
    @ResponseBody
    @Permission("login")
    public Object getOutlets(@RequestBody String jsonstring){
    	LogUtil.info("/getOutlets>>>" + jsonstring);
    	Map<String, Object>  map=new HashMap<String,Object>();
    	try {
	    	JSONObject object = JSONObject.fromObject(jsonstring);
	        ArrayList<String> arraylist =new ArrayList<String>();
            arraylist.add("latitudeX");
            arraylist.add("longitudeY");
            arraylist.add("page");
            arraylist.add("linage");
            boolean flag = CheckUtil.checkParameter(object,arraylist);
            if(!flag){
                LogUtil.error("参数输入错误");
                map.put("code", 20002);
                map.put("mes", "参数输入错误");
                return  map;
            }
            map=appStoreService.getOutlets(object);
    	}catch(Exception e){
    		LogUtil.error(e.getMessage());
            map.put("code", 30000);
            map.put("mes", e.getMessage());
    	}
    	return map;
    }
    /**
     * 品牌网店
     * @function  getBrand
     * @author lutao
     * @createTime 2017年3月1日
     * @param 
     */
    @RequestMapping(value="/getBrand")
    @ResponseBody
    @Permission("login")
    public Object getBrand(@RequestBody String jsonstring){
    	LogUtil.info("/getBrand>>>" + jsonstring);
    	Map<String, Object>  map=new HashMap<String,Object>();
    	try {
	    	JSONObject object = JSONObject.fromObject(jsonstring);
	        ArrayList<String> arraylist =new ArrayList<String>();
            arraylist.add("page");
            arraylist.add("linage");
            boolean flag = CheckUtil.checkParameter(object,arraylist);
            if(!flag){
                LogUtil.error("参数输入错误");
                map.put("code", 20002);
                map.put("mes", "参数输入错误");
                return  map;
            }
            map=appBrandWebsiteService.getBrand(object);
    	}catch(Exception e){
    		LogUtil.error(e.getMessage());
            map.put("code", 30000);
            map.put("mes", e.getMessage());
    	}
    	return map;
    }
    
    /**
     * 评价
     * @function  evaluate
     * @author lutao
     * @createTime 2017年3月1日
     * @param 
     */
    @RequestMapping(value="/evaluate")
    @ResponseBody
    @Permission("login")
    public Object evaluate(@RequestBody String jsonstring){
    	LogUtil.info("/getBrand>>>" + jsonstring);
    	Map<String, Object>  map=new HashMap<String,Object>();
    	try {
	    	JSONObject object = JSONObject.fromObject(jsonstring);
	        ArrayList<String> arraylist =new ArrayList<String>();
            arraylist.add("orderNo");
            arraylist.add("evaluate");
            arraylist.add("attitudeStar");
            arraylist.add("starMaintenance");
            boolean flag = CheckUtil.checkParameter(object,arraylist);
            if(!flag){
                LogUtil.error("参数输入错误");
                map.put("code", 20002);
                map.put("mes", "参数输入错误");
                return  map;
            }
            map=appEvaluateService.evaluate(object);
    	}catch(Exception e){
    		LogUtil.error(e.getMessage());
            map.put("code", 30000);
            map.put("mes", e.getMessage());
    	}
    	return map;
    }
    
    /**
     * 轮播图
     * @function  repair_carousel
     * @author lutao
     * @createTime 2017年3月1日
     * @param 
     */
    @RequestMapping(value="/repair_carousel")
    @ResponseBody
    @Permission("login")
    public Object repair_carousel(@RequestBody String jsonstring){
    	LogUtil.info("/getBrand>>>" + jsonstring);
    	Map<String, Object>  map=new HashMap<String,Object>();
    	try {
	    	JSONObject object = JSONObject.fromObject(jsonstring);
            map=appFigurephotoService.repair_carousel(object);
    	}catch(Exception e){
    		LogUtil.error(e.getMessage());
            map.put("code", 30000);
            map.put("mes", e.getMessage());
    	}
    	return map;
    }
}
